package com.huawei.hianalytics.ab.bc.kl;

import android.annotation.TargetApi;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.URLUtil;
import com.huawei.hianalytics.ab.gh.ab;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;

public class fg {
    private static final String[] ab = new String[]{"dbankcloud.com", "dbankcloud.cn", "dbankcloud.eu", "dbankcloud.asia", "digitalincloud.com", "digitalincloud.cn", "digitalincloud.eu", "digitalincloud.asia", "dbankcdn.com", "dbankcdn.cn", "dbankcdn.eu", "dbankcdn.asia", "hicloud.com"};

    public static boolean ab(String str) {
        if (ab.ab.booleanValue()) {
            return true;
        }
        for (String ab : ab) {
            if (ab(str, ab)) {
                return true;
            }
        }
        return false;
    }

    public static boolean ab(String str, String str2) {
        String bc = bc(str);
        if (TextUtils.isEmpty(bc) || TextUtils.isEmpty(str2)) {
            com.huawei.hianalytics.ab.bc.ef.ab.de("UriUtil", "url or whitelist is null");
            return false;
        }
        String cd = cd(str2);
        if (TextUtils.isEmpty(cd)) {
            Log.e("UriUtil", "whitelist host is null");
            return false;
        } else if (cd.equals(bc)) {
            return true;
        } else {
            if (!bc.endsWith(cd)) {
                return false;
            }
            try {
                bc = bc.substring(0, bc.length() - cd.length());
                return bc.endsWith(".") ? bc.matches("^[A-Za-z0-9.-]+$") : false;
            } catch (IndexOutOfBoundsException e) {
                com.huawei.hianalytics.ab.bc.ef.ab.de("UriUtil", "IndexOutOfBoundsException" + e.getMessage());
                return false;
            } catch (Exception e2) {
                com.huawei.hianalytics.ab.bc.ef.ab.de("UriUtil", "Exception : " + e2.getMessage());
                return false;
            }
        }
    }

    @TargetApi(9)
    public static String bc(String str) {
        if (TextUtils.isEmpty(str)) {
            com.huawei.hianalytics.ab.bc.ef.ab.bc("UriUtil", "url is null");
            return str;
        }
        try {
            if (URLUtil.isNetworkUrl(str) && !str.toLowerCase(Locale.US).startsWith("http:")) {
                return new URI(str).getHost();
            }
            com.huawei.hianalytics.ab.bc.ef.ab.de("UriUtil", "url don't starts with https");
            return null;
        } catch (URISyntaxException e) {
            com.huawei.hianalytics.ab.bc.ef.ab.de("UriUtil", "getHostByURI error : " + e.getMessage());
            return null;
        }
    }

    private static String cd(String str) {
        if (!TextUtils.isEmpty(str)) {
            return URLUtil.isNetworkUrl(str) ? bc(str) : str;
        } else {
            com.huawei.hianalytics.ab.bc.ef.ab.bc("UriUtil", "whiteListUrl is null");
            return null;
        }
    }
}
